package com.cx.caigou.baojia.controller;

import com.cx.caigou.baojia.model.*;
import com.cx.caigou.baojia.service.BaoJiaService;
import com.cx.caigou.config.ResultVO;
import com.cx.caigou.config.ResultVOBuilder;
import com.cx.caigou.util.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@CrossOrigin
@RestController
public class BaoJiaController {

    @Autowired
    private BaoJiaService baoJiaService;

    /*
    * 报价状态/类型/币别/含税
    * */
    @PostMapping("procurement/getPullDownList")
    public ResultVO getPullDownList(){
        HashMap<String , List<StatusVo>> map = new HashMap<>();
        //状态
        List<StatusVo> listStatus = new ArrayList<>();
        for (StatusEnum s:StatusEnum.values()) {
            StatusVo statusVo = new StatusVo();
            statusVo.setLabel(s.getStatusName());
            statusVo.setValue(s.getStatus());
            listStatus.add(statusVo);
        }
        map.put("biddingStatus",listStatus);



        //询价类型
        ArrayList<StatusVo> listType = new ArrayList<>();
        for (TypeEnum s:TypeEnum.values()) {
            StatusVo statusVo = new StatusVo();
            statusVo.setLabel(s.getStatusName());
            statusVo.setValue(s.getStatus());
            listType.add(statusVo);
        }
        map.put("type",listType);

        //含税
        ArrayList<StatusVo> listTax = new ArrayList<>();
        for (TaxEnum s:TaxEnum.values()) {
            StatusVo statusVo = new StatusVo();
            statusVo.setLabel(s.getStatusName());
            statusVo.setValue(s.getStatus());
            listTax.add(statusVo);
        }
        map.put("isTax",listTax);

        //币别
        ArrayList<StatusVo> listCurrencyCode = new ArrayList<>();
        for (CurrencyCodeEnum s:CurrencyCodeEnum.values()) {
            StatusVo statusVo = new StatusVo();
            statusVo.setLabel(s.getStatusName());
            statusVo.setValue(s.getStatus());
            listCurrencyCode.add(statusVo);
        }
        map.put("currencyCode",listCurrencyCode);
        return ResultVOBuilder.success(map);
    }
    /*
    * 报价列表分页查询
    * */
    @PostMapping("quotationList/searchPre")
    public ResultVO query(@RequestBody  BaoJiaSelect baoJiaSelect){
        System.out.println("111111");
        return baoJiaService.query(baoJiaSelect);
    }

    //获取税率列表
    @PostMapping("tax/findTaxDuplicateRemovalList")
    public ResultVO findTaxDuplicateRemovalList(){
        return null;
    }
    /*
    * 报价对象
    * */
    @PostMapping("partner/queryLegalPerson")
    @ApiOperation(value = "报价对象")
    public ResultVO queryByLegalPerson(Integer legalPersonId){

        return null;
    }
    /*
    *查看报价但列表
    */
    @GetMapping("quotationList/findByCoding")
    public ResultVO findByCoding(){
        return null;
    }
    /*
     * 导入
     * */

    @PostMapping("quotation/QuotationIntroduction")
    public ResultVO importFile(MultipartFile file)throws Exception{
        System.out.println(file.getOriginalFilename());
        if (!file.getOriginalFilename().contains("xlsx")){
            return ResultVOBuilder.error("请检查导入模板，尾缀名必须为xlsx");
        }

        ResultVO resultVO = baoJiaService.importFile(file);

        return ResultVOBuilder.success(resultVO);

    }
    /*
    * 新增
    * */
    @PostMapping("quotation/add")
    public ResultVO add(@RequestBody BaoJiaAdd baoJiaAdd , BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultVOBuilder.error(bindingResult.getFieldError().getDefaultMessage());

        }
        return baoJiaService.add(baoJiaAdd);
    }

    /*
    * 报价清单分页
    * */
    @PostMapping("quotationSheet/search")
    public ResultVO<AllrecordsVo<QuptationReturnVo>> search(SearvhVo searvhVo){

        return baoJiaService.search(searvhVo);
    }

    /*
    *查看
     */
    @PostMapping("quotation/see")
    public ResultVO search(@RequestBody Dan id){
        System.out.println(id.getQuotationNumber());
        return baoJiaService.see(id.getQuotationNumber());
    }


}
